package de.openkanban.client.ui.presenter;

import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.Response;
import com.smartgwt.client.util.SC;

import de.openkanban.client.util.RootPanel;
import de.openkanban.shared.dto.StatusDto;

/**
 * Callback that handles new available contact request
 */
public class NewAvailableContactRequestCallback implements RequestCallback {

	@Override
	public void onResponseReceived(Request request, Response response) {

		if (response.getStatusCode() == 500) {
			SC.say(response.getText());
		}

		StatusDto statusDto = new StatusDto(response.getText());

		if (statusDto.getFehlerKz() > 0) {
			SC.say(statusDto.getFehlerText() + " (NewAvailableContact: " + statusDto.getFehlerKz() + ")");
		}

		RootPanel.main.getFooter().updateUserContactsData();
	}

	@Override
	public void onError(Request request, Throwable exception) {
		throw new RuntimeException(request.toString(), exception);
	}

}
